/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package itproject.clients.gui;

import itproject.data.Customer;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author tim
 */
public class CustomerTableModel extends AbstractTableModel {

    private Vector<Customer> customers;
    private static final int ID_INDEX = 0;
    private static final int FIRSTNAME_INDEX = 1;
    private static final int LASTNAME_INDEX = 2;
    private static final int STREET_INDEX = 3;
    private static final int CITY_INDEX = 4;
    private static final int ZIP_INDEX = 5;
    private static final int OBJECT = 6;
    private String[] columnNames = {"ID", "First Name", "Last Name", "Street", "City", "Zip"};

    public CustomerTableModel(Vector<Customer> c) {
        customers = c;
    }
    

    public int getRowCount() {
        return customers.size();
    }

    public int getColumnCount() {
        return columnNames.length;

    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Object getValueAt(int rowIndex, int columnIndex) {

        Customer c = (Customer) customers.get(rowIndex);
        switch (columnIndex) {
            case ID_INDEX:
                return c.getCustomerId();
            case FIRSTNAME_INDEX:
                return c.getFirstname();
            case LASTNAME_INDEX:
                return c.getLastname();
            case STREET_INDEX:
                return c.getStreet();
            case ZIP_INDEX:
                return c.getZip();
            case CITY_INDEX:
                return c.getCity();
            case OBJECT:
                return c;

            default:
                return new Object();
        }
    }



}

